import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class Main {
    public static String formattedString;

    public static void main(String[] args) {
        // 创建窗口
        JFrame frame = new JFrame("Awei.Qi");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 500);
        frame.setLayout(new GridBagLayout());
        frame.setLocationRelativeTo(null); // 窗口居中

        // 创建面板
        JPanel panel = new JPanel();
        panel.setBackground(Color.LIGHT_GRAY);
        panel.setLayout(new GridBagLayout());

        // 创建文本框
        Font font = new Font("Serif", Font.BOLD, 30);
        JTextField inputField = new JTextField();
        inputField.setFont(font);
        inputField.setPreferredSize(new Dimension(500, 60)); // 调整文本框尺寸

        // 添加按键监听器
        inputField.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {}

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    String inputText = inputField.getText().trim();
                    if (!inputText.isEmpty()) {
                        String replacedText = inputText.replaceAll(" ", "',\n'");
                        formattedString = "('" + replacedText + "')";
                        System.out.println(formattedString);
                    } else {
                        System.out.println("输入为空，请重新输入！");
                    }
                }
            }

            @Override
            public void keyReleased(KeyEvent e) {}
        });

        // 设置布局约束
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.insets = new Insets(20, 20, 20, 20); // 设置边距
        gbc.fill = GridBagConstraints.HORIZONTAL;

        // 将文本框添加到面板
        panel.add(inputField, gbc);

        // 将面板添加到窗口
        frame.add(panel);

        // 显示窗口
        frame.setVisible(true);
    }
}